class Admin::SeckillTimesController < AdminController
  def index
    @seckill_times = SeckillTime.all.order("name ASC")
  end

  def show
    @seckill_time = SeckillTime.find params[:id]
  end

  def new
    @seckill_time = SeckillTime.new
  end
  
  def create
    @seckill_time = SeckillTime.new seckill_time_params
    if @seckill_time.save
      redirect_to admin_seckill_times_path, notice: "新增成功！"
    else
      redirect_to admin_seckill_times_path, notice: "新增失败！"
    end
  end

  def edit
    @seckill_time = SeckillTime.find params[:id]
  end

  def update
    @seckill_time = SeckillTime.find params[:id]
    if @seckill_time.update seckill_time_params
      redirect_to admin_seckill_times_path, notice: "更新成功！"
    else
      redirect_to admin_seckill_times_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @seckill_time = SeckillTime.find params[:id]
    if @seckill_time.destroy
      redirect_to admin_seckill_times_path, notice: "删除成功."
    else
      redirect_to admin_seckill_times_path, notice: "删除失败."
    end
  end

  private

  def seckill_time_params
    params.require(:seckill_time).permit(:name)
  end
end
